﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utility.Database
{
    public class Sql
    {
        #region 成员变量
        private string _SqlText;
        private Parameter _Parameter;
        #endregion

        #region 构造函数

        public Sql()
        {
            this._SqlText = "";
            this._Parameter = new Parameter();
        }

        public Sql(string sqlText)
        {
            this._SqlText = sqlText;
            this._Parameter = new Parameter();
        }

        public Sql(string sqlText, Parameter parameter)
        {
            this._SqlText = sqlText;
            this._Parameter = parameter;
        }
        #endregion

        #region 属性

        #region SqlText
        public string SqlText
        {
            get
            {
                return this._SqlText;
            }

            set
            {
                this._SqlText = value;
            }
        }
        #endregion

        #region Parameter
        public Parameter Parameter
        {
            get
            {
                return this._Parameter;
            }

            set
            {
                this._Parameter = value;
            }
        }
        #endregion
        #endregion

        #region 方法
        #region Build
        public string Build()
        {
            string resultSqlText = this._SqlText;
            for (int i = 0; i < this._Parameter.Count; i++)
            {
                resultSqlText = resultSqlText.Replace(_Parameter[i].Name, _Parameter[i].Value);
            }

            return resultSqlText;
        }
        #endregion

        #region Clear
        public void Clear()
        {
            this._SqlText = "";
            this._Parameter.Clear();
        }
        #endregion
        #endregion
    }
}
